﻿@model IEnumerable<BBICMS.DTO.MenuDTO>
@using BBICMS.Infrastructure.UI;

@{ 
    int i = 0;
}

@helper ShowTree(IEnumerable<BBICMS.DTO.MenuDTO> menus, int i)
{
i++;
string className = (i == 1) ? "mainmenu" : "submenu";

    <ul class="list-unstyled @className">
        @foreach (var item in menus)
        {

            bool isCurrent = (string.Compare(Html.Controller(), item.Controller, true) == 0 &&
                string.Compare(Html.Action(), item.Action, true) == 0 && string.Compare(Html.Area(), item.Area, true) == 0);

            string active = isCurrent ? "active" : "";
            string openClass = item.ChildMenus.Where(m => string.Compare(m.Area, Html.Area(), true) == 0 &&
            string.Compare(m.Controller, Html.Controller(), true) == 0 &&
            string.Compare(m.Action , Html.Action(),true)==0 && m.Active && m.MenuType == MenuType.PAGE).Any() ? "nav-open" : "";
            string downNav = item.ChildMenus.Where(m => m.Active && m.MenuType == MenuType.PAGE).Any() ? "down-nav" : "";
            string url = string.IsNullOrEmpty(item.Url) ? "#" : item.Url;

            <li class="liitem @downNav @openClass">
                <a href="@url" class="@active">
                    <i class="@item.Iconfont fa-fw"></i>@item.Title
                    @{
                        if (item.ChildMenus.Where(m => m.Active && m.MenuType == MenuType.PAGE).Any())
                        {
                            <span class="badge">@item.ChildMenus.Where(m => m.Active).Count()</span>
                        }
                    }
                </a>
                @if (item.ChildMenus.Where(m => m.Active && m.MenuType == MenuType.PAGE).Any())
                {
                    @ShowTree(item.ChildMenus.Where(m => m.Active && m.MenuType == MenuType.PAGE).OrderByDescending(c => c.Importance), i)
                }
            </li>
            }        
    </ul>
}


<div id="sidebar-nav" class="leftcol">

    <aside>
        <nav id="menu">
            <h3>导航</h3>
            @ShowTree(Model, i)
        </nav>
        <div class="closemenu">
            <a href="#"><i class="fa fa-chevron-circle-left"></i></a>
        </div>
    </aside>

</div>
